"""
System level test for DoA processing

---

- Copyright (C) 2018 - PRESENT  radarsimx.com
- E-mail: info@radarsimx.com
- Website: https://radarsimx.com

::

    ██████╗  █████╗ ██████╗  █████╗ ██████╗ ███████╗██╗███╗   ███╗██╗  ██╗
    ██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔══██╗██╔════╝██║████╗ ████║╚██╗██╔╝
    ██████╔╝███████║██║  ██║███████║██████╔╝███████╗██║██╔████╔██║ ╚███╔╝ 
    ██╔══██╗██╔══██║██║  ██║██╔══██║██╔══██╗╚════██║██║██║╚██╔╝██║ ██╔██╗ 
    ██║  ██║██║  ██║██████╔╝██║  ██║██║  ██║███████║██║██║ ╚═╝ ██║██╔╝ ██╗
    ╚═╝  ╚═╝╚═╝  ╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝╚═╝     ╚═╝╚═╝  ╚═╝

"""

import numpy as np
import numpy.testing as npt

import radarsimpy.processing as proc


covmat_est = np.array(
    [
        [
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601430 * 1j,
            2.26109130412416 + 0.989143898037957 * 1j,
            -0.378365978640197 + 0.889536536650390 * 1j,
            1.13549289576738 + 0.552382221616346 * 1j,
            -0.990501697296642 - 0.183694849224894 * 1j,
            1.28472431753472 - 0.629797821850576 * 1j,
            -0.136214149861948 - 1.07377729071515 * 1j,
            2.48622500160235 - 0.775783252972922 * 1j,
            0.925034243757439 - 0.501055069082895 * 1j,
            2.96213213022416 + 0.365264316268174 * 1j,
        ],
        [
            0.794230483767640 - 0.595755572601430 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601430 * 1j,
            2.26109130412416 + 0.989143898037955 * 1j,
            -0.378365978640197 + 0.889536536650388 * 1j,
            1.13549289576738 + 0.552382221616346 * 1j,
            -0.990501697296642 - 0.183694849224890 * 1j,
            1.28472431753472 - 0.629797821850576 * 1j,
            -0.136214149861947 - 1.07377729071516 * 1j,
            2.48622500160235 - 0.775783252972922 * 1j,
            0.925034243757439 - 0.501055069082895 * 1j,
        ],
        [
            2.26109130412416 - 0.989143898037957 * 1j,
            0.794230483767640 - 0.595755572601430 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601431 * 1j,
            2.26109130412416 + 0.989143898037957 * 1j,
            -0.378365978640197 + 0.889536536650388 * 1j,
            1.13549289576738 + 0.552382221616343 * 1j,
            -0.990501697296642 - 0.183694849224890 * 1j,
            1.28472431753472 - 0.629797821850573 * 1j,
            -0.136214149861947 - 1.07377729071516 * 1j,
            2.48622500160235 - 0.775783252972922 * 1j,
        ],
        [
            -0.378365978640197 - 0.889536536650390 * 1j,
            2.26109130412416 - 0.989143898037955 * 1j,
            0.794230483767640 - 0.595755572601431 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601428 * 1j,
            2.26109130412416 + 0.989143898037959 * 1j,
            -0.378365978640197 + 0.889536536650390 * 1j,
            1.13549289576738 + 0.552382221616345 * 1j,
            -0.990501697296642 - 0.183694849224896 * 1j,
            1.28472431753472 - 0.629797821850571 * 1j,
            -0.136214149861947 - 1.07377729071516 * 1j,
        ],
        [
            1.13549289576738 - 0.552382221616346 * 1j,
            -0.378365978640197 - 0.889536536650388 * 1j,
            2.26109130412416 - 0.989143898037957 * 1j,
            0.794230483767640 - 0.595755572601428 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601430 * 1j,
            2.26109130412416 + 0.989143898037953 * 1j,
            -0.378365978640197 + 0.889536536650392 * 1j,
            1.13549289576738 + 0.552382221616346 * 1j,
            -0.990501697296642 - 0.183694849224894 * 1j,
            1.28472431753472 - 0.629797821850573 * 1j,
        ],
        [
            -0.990501697296642 + 0.183694849224894 * 1j,
            1.13549289576738 - 0.552382221616346 * 1j,
            -0.378365978640197 - 0.889536536650388 * 1j,
            2.26109130412416 - 0.989143898037959 * 1j,
            0.794230483767640 - 0.595755572601430 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601433 * 1j,
            2.26109130412416 + 0.989143898037953 * 1j,
            -0.378365978640197 + 0.889536536650388 * 1j,
            1.13549289576738 + 0.552382221616346 * 1j,
            -0.990501697296642 - 0.183694849224894 * 1j,
        ],
        [
            1.28472431753472 + 0.629797821850576 * 1j,
            -0.990501697296642 + 0.183694849224890 * 1j,
            1.13549289576738 - 0.552382221616343 * 1j,
            -0.378365978640197 - 0.889536536650390 * 1j,
            2.26109130412416 - 0.989143898037953 * 1j,
            0.794230483767640 - 0.595755572601433 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767641 + 0.595755572601429 * 1j,
            2.26109130412415 + 0.989143898037960 * 1j,
            -0.378365978640198 + 0.889536536650384 * 1j,
            1.13549289576738 + 0.552382221616349 * 1j,
        ],
        [
            -0.136214149861948 + 1.07377729071515 * 1j,
            1.28472431753472 + 0.629797821850576 * 1j,
            -0.990501697296642 + 0.183694849224890 * 1j,
            1.13549289576738 - 0.552382221616345 * 1j,
            -0.378365978640197 - 0.889536536650392 * 1j,
            2.26109130412416 - 0.989143898037953 * 1j,
            0.794230483767641 - 0.595755572601429 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601427 * 1j,
            2.26109130412415 + 0.989143898037961 * 1j,
            -0.378365978640198 + 0.889536536650384 * 1j,
        ],
        [
            2.48622500160235 + 0.775783252972922 * 1j,
            -0.136214149861947 + 1.07377729071516 * 1j,
            1.28472431753472 + 0.629797821850573 * 1j,
            -0.990501697296642 + 0.183694849224896 * 1j,
            1.13549289576738 - 0.552382221616346 * 1j,
            -0.378365978640197 - 0.889536536650388 * 1j,
            2.26109130412415 - 0.989143898037960 * 1j,
            0.794230483767640 - 0.595755572601427 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601429 * 1j,
            2.26109130412416 + 0.989143898037957 * 1j,
        ],
        [
            0.925034243757439 + 0.501055069082895 * 1j,
            2.48622500160235 + 0.775783252972922 * 1j,
            -0.136214149861947 + 1.07377729071516 * 1j,
            1.28472431753472 + 0.629797821850571 * 1j,
            -0.990501697296642 + 0.183694849224894 * 1j,
            1.13549289576738 - 0.552382221616346 * 1j,
            -0.378365978640198 - 0.889536536650384 * 1j,
            2.26109130412415 - 0.989143898037961 * 1j,
            0.794230483767640 - 0.595755572601429 * 1j,
            3.63095734448019 + 0 * 1j,
            0.794230483767640 + 0.595755572601430 * 1j,
        ],
        [
            2.96213213022416 - 0.365264316268174 * 1j,
            0.925034243757439 + 0.501055069082895 * 1j,
            2.48622500160235 + 0.775783252972922 * 1j,
            -0.136214149861947 + 1.07377729071516 * 1j,
            1.28472431753472 + 0.629797821850573 * 1j,
            -0.990501697296642 + 0.183694849224894 * 1j,
            1.13549289576738 - 0.552382221616349 * 1j,
            -0.378365978640198 - 0.889536536650384 * 1j,
            2.26109130412416 - 0.989143898037957 * 1j,
            0.794230483767640 - 0.595755572601430 * 1j,
            3.63095734448019 + 0 * 1j,
        ],
    ]
)


covmat_beamforming = np.array(
    [
        [
            2.86435060461735 + 0.00000000000000 * 1j,
            0.811085737295669 + 1.30227444234303 * 1j,
            0.504301040881477 - 1.00998726806392 * 1j,
            2.72241657929298 - 0.293426536427853 * 1j,
            1.09558286982305 + 1.38724422911377 * 1j,
            0.286520259490070 - 0.792684934007848 * 1j,
            2.59161897333798 - 0.571047494844847 * 1j,
            1.42573311924613 + 1.43217324415322 * 1j,
            0.118079636383169 - 0.521144536970471 * 1j,
            2.43231179623868 - 0.825198584873097 * 1j,
        ],
        [
            0.811085737295669 - 1.30227444234303 * 1j,
            1.84755785331360 + 0.00000000000000 * 1j,
            0.178505290257218 + 0.275885649529008 * 1j,
            0.590249850740701 - 1.26238094293594 * 1j,
            1.79764115658081 - 0.224283298581727 * 1j,
            0.350370057845123 + 0.409182384664349 * 1j,
            0.400773288203037 - 1.15485009350202 * 1j,
            1.81954310603571 - 0.450433700515389 * 1j,
            0.526337242157251 + 0.520857218534430 * 1j,
            0.238850024243051 - 1.04227619126101 * 1j,
        ],
        [
            0.504301040881477 + 1.00998726806392 * 1j,
            0.178505290257218 - 0.275885649529008 * 1j,
            1.57731393536759 + 0.00000000000000 * 1j,
            0.667853435228749 + 1.05824168244305 * 1j,
            0.0631825165171450 - 0.146604502325945 * 1j,
            1.40141246609957 - 0.172573228634075 * 1j,
            0.836133348163892 + 1.05202595933996 * 1j,
            -0.0222793576021373 + 0.0128971713330377 * 1j,
            1.28709132798692 - 0.305699150588609 * 1j,
            1.01531794499543 + 1.00698197341080 * 1j,
        ],
        [
            2.72241657929298 + 0.293426536427853 * 1j,
            0.590249850740701 + 1.26238094293594 * 1j,
            0.667853435228749 - 1.05824168244305 * 1j,
            2.83089465902566 + 0.00000000000000 * 1j,
            0.869864607055596 + 1.39263044682422 * 1j,
            0.421330219272654 - 0.879917604633588 * 1j,
            2.64391169464408 - 0.294939501634435 * 1j,
            1.17982086503835 + 1.48927734106737 * 1j,
            0.210277325342498 - 0.645457934411830 * 1j,
            2.53414257439438 - 0.573735940299302 * 1j,
        ],
        [
            1.09558286982305 - 1.38724422911377 * 1j,
            1.79764115658081 + 0.224283298581727 * 1j,
            0.0631825165171450 + 0.146604502325945 * 1j,
            0.869864607055596 - 1.39263044682422 * 1j,
            2.00142763771913 + 0.00000000000000 * 1j,
            0.208501874874084 + 0.328808413816868 * 1j,
            0.639122890517293 - 1.32641599742298 * 1j,
            1.98057450088836 - 0.230695099267132 * 1j,
            0.377082982336631 + 0.488883425703061 * 1j,
            0.437323828270626 - 1.24168453560702 * 1j,
        ],
        [
            0.286520259490070 + 0.792684934007848 * 1j,
            0.350370057845123 - 0.409182384664349 * 1j,
            1.40141246609957 + 0.172573228634075 * 1j,
            0.421330219272654 + 0.879917604633588 * 1j,
            0.208501874874084 - 0.328808413816868 * 1j,
            1.48342702293691 + 0.00000000000000 * 1j,
            0.573651709810074 + 0.926403794323357 * 1j,
            0.0891883928322622 - 0.208799328917923 * 1j,
            1.32322181458357 - 0.144880533222894 * 1j,
            0.732208466569336 + 0.931568908687762 * 1j,
        ],
        [
            2.59161897333798 + 0.571047494844847 * 1j,
            0.400773288203037 + 1.15485009350202 * 1j,
            0.836133348163892 - 1.05202595933996 * 1j,
            2.64391169464408 + 0.294939501634435 * 1j,
            0.639122890517293 + 1.32641599742298 * 1j,
            0.573651709810074 - 0.926403794323357 * 1j,
            2.71197504118315 + 0.00000000000000 * 1j,
            0.922746605912398 + 1.47213235151886 * 1j,
            0.334424544527173 - 0.728483476348702 * 1j,
            2.55103473133829 - 0.283499225800758 * 1j,
        ],
        [
            1.42573311924613 - 1.43217324415322 * 1j,
            1.81954310603571 + 0.450433700515389 * 1j,
            -0.0222793576021373 - 0.0128971713330377 * 1j,
            1.17982086503835 - 1.48927734106737 * 1j,
            1.98057450088836 + 0.230695099267132 * 1j,
            0.0891883928322622 + 0.208799328917923 * 1j,
            0.922746605912398 - 1.47213235151886 * 1j,
            2.21104428515168 + 0.00000000000000 * 1j,
            0.237978013333236 + 0.418915096142743 * 1j,
            0.690083397770649 - 1.42565896476598 * 1j,
        ],
        [
            0.118079636383169 + 0.521144536970471 * 1j,
            0.526337242157251 - 0.520857218534430 * 1j,
            1.28709132798692 + 0.305699150588609 * 1j,
            0.210277325342498 + 0.645457934411830 * 1j,
            0.377082982336631 - 0.488883425703061 * 1j,
            1.32322181458357 + 0.144880533222894 * 1j,
            0.334424544527173 + 0.728483476348702 * 1j,
            0.237978013333236 - 0.418915096142743 * 1j,
            1.40306815180544 + 0.00000000000000 * 1j,
            0.476886381373807 + 0.778173010784313 * 1j,
        ],
        [
            2.43231179623868 + 0.825198584873097 * 1j,
            0.238850024243051 + 1.04227619126101 * 1j,
            1.01531794499543 - 1.00698197341080 * 1j,
            2.53414257439438 + 0.573735940299302 * 1j,
            0.437323828270626 + 1.24168453560702 * 1j,
            0.732208466569336 - 0.931568908687762 * 1j,
            2.55103473133829 + 0.283499225800758 * 1j,
            0.690083397770649 + 1.42565896476598 * 1j,
            0.476886381373807 - 0.778173010784313 * 1j,
            2.62424195047423 + 0.00000000000000 * 1j,
        ],
    ]
)

bv = np.array(
    [
        -0.01186689 - 0.04185796j,
        -0.03986594 + 0.05981525j,
        0.04653831 + 0.00296619j,
        -0.03029594 - 0.03835375j,
        -0.03083453 + 0.05260952j,
        0.04508425 - 0.01282615j,
        -0.04299936 - 0.02802899j,
        0.00927348 + 0.05539008j,
        0.04850148 - 0.03266233j,
        -0.04251513 - 0.0038775j,
        0.03138971 + 0.05365343j,
        0.02867087 - 0.03635999j,
        -0.04786291 + 0.03188547j,
        0.04730786 + 0.0566073j,
        -0.0023872 - 0.02735395j,
        -0.0571707 + 0.05395322j,
        0.03334938 + 0.03918208j,
        -0.03919735 - 0.03348234j,
        -0.06255109 + 0.05654166j,
        0.01204984 - 0.00172678j,
        -0.07797436 - 0.05022818j,
        -0.04349277 + 0.03979636j,
        0.00889777 - 0.05860273j,
        -0.07412077 - 0.06463466j,
        -0.00313349 + 0.00709387j,
        0.03183294 - 0.08617971j,
        -0.04779437 - 0.06260542j,
        0.04774767 - 0.01322903j,
        0.05353402 - 0.09785517j,
        -0.0056576 - 0.02415712j,
        0.10013926 + 0.00450789j,
        0.06309816 - 0.08108032j,
        0.02327119 + 0.04580729j,
        0.11618184 + 0.02738891j,
        0.03568155 - 0.0100348j,
        0.02690858 + 0.09686453j,
        0.09439313 + 0.06155378j,
        -0.01119218 + 0.04111582j,
        0.00134046 + 0.13552852j,
        0.02926106 + 0.05231344j,
        -0.08997227 + 0.05924138j,
        -0.03456733 + 0.11743561j,
        -0.03925567 + 0.01141581j,
        -0.13488628 + 0.03572039j,
        -0.05543908 + 0.04548292j,
        -0.08267488 - 0.06476465j,
        -0.13869512 - 0.01206525j,
        -0.02970982 - 0.02849605j,
        -0.07242724 - 0.12887301j,
        -0.08171976 - 0.0440587j,
        0.03685305 - 0.09346036j,
        -0.02149517 - 0.1479362j,
        0.01754473 - 0.04686218j,
        0.1081823 - 0.10205556j,
        0.03146289 - 0.10719739j,
        0.08603354 + 0.00172431j,
        0.14793527 - 0.06113406j,
        0.05965853 - 0.01802525j,
        0.12271691 + 0.07320228j,
        0.11886408 + 0.00055866j,
        0.03123025 + 0.07803919j,
        0.09486276 + 0.13011814j,
        0.03929061 + 0.05048563j,
        -0.0375638 + 0.13469318j,
        0.02945265 + 0.13587593j,
        -0.05798158 + 0.04575383j,
        -0.09678429 + 0.13839304j,
        -0.03308871 + 0.06900257j,
        -0.12030037 + 0.01033336j,
        -0.11775612 + 0.07223885j,
        -0.05281892 - 0.03267847j,
        -0.14120325 - 0.05295036j,
        -0.08642548 + 0.00292703j,
        -0.03347659 - 0.10423995j,
        -0.10770959 - 0.09513838j,
        -0.00769193 - 0.05810092j,
        0.01361541 - 0.14494189j,
        -0.02398713 - 0.08792752j,
        0.07881023 - 0.05453722j,
        0.05546929 - 0.1244134j,
        0.03284855 - 0.0206271j,
        0.13965583 - 0.03523023j,
        0.06967714 - 0.06002399j,
        0.05665267 + 0.05710011j,
        0.13883879 + 0.02186198j,
        0.03338582 + 0.01193417j,
        0.04731693 + 0.10937894j,
        0.08668919 + 0.04673403j,
        -0.026182 + 0.05673588j,
        0.01690545 + 0.13774023j,
        0.01458907 + 0.0383881j,
        -0.0820339 + 0.06645166j,
        -0.01258085 + 0.09813232j,
        -0.04823295 - 0.00976428j,
        -0.11383883 + 0.04142284j,
        -0.02382921 + 0.03508765j,
        -0.07009024 - 0.06180211j,
        -0.09652661 + 0.00509228j,
        -0.00219461 - 0.02257629j,
        -0.05937509 - 0.09535567j,
        -0.04393338 - 0.0088692j,
        0.03533861 - 0.066135j,
        -0.03129275 - 0.07785461j,
        0.01009301 - 0.00041474j,
        0.06445948 - 0.06399579j,
        -0.01228821 - 0.0509649j,
        0.04833974 + 0.02175187j,
        0.05938164 - 0.04883014j,
        -0.00444837 - 0.00393257j,
        0.06703226 + 0.04341363j,
        0.03448898 - 0.03237542j,
        -0.02494928 + 0.03597139j,
        0.06450764 + 0.04506148j,
        -0.00764947 - 0.02534106j,
        -0.02752489 + 0.05561603j,
        0.04459235 + 0.01792268j,
        -0.03330761 - 0.02604964j,
        -0.02693534 + 0.04991622j,
        0.03494827 - 0.01248508j,
        -0.04677906 - 0.02480979j,
        0.00834992 + 0.04730467j,
        0.03803558 - 0.03099997j,
        -0.04751946 - 0.00775298j,
        0.02598464 + 0.04234132j,
        0.02450016 - 0.02745242j,
        -0.03905045 + 0.01991701j,
        0.03432705 + 0.05323918j,
        0.00468051 - 0.02905531j,
    ]
)


def test_doa_music():
    """
    This function tests the DOA MUSIC algorithm.
    """
    doa, _, _ = proc.doa_music(covmat_est, 3)

    npt.assert_equal(np.sort(doa), np.array([-12, 0, 85]))


def test_doa_root_music():
    """
    Test the DOA (Direction of Arrival) estimation using root MUSIC algorithm.
    """
    doa = proc.doa_root_music(covmat_est, 3)

    npt.assert_almost_equal(
        np.sort(doa),
        np.array([-1.19999999e01, 1.73229939e-07, 8.49999996e01]),
        decimal=3,
    )


def test_doa_esprit():
    """
    Test the DOA (Direction of Arrival) estimation using the ESPRIT algorithm.
    """
    doa = proc.doa_esprit(covmat_est, 3)

    npt.assert_almost_equal(doa, np.array([2.025e-15, -1.200e01, 8.500e01]), decimal=3)


def test_doa_iaa():
    """
    Test the DOA (Direction of Arrival) estimation using the IAA algorithm.
    """
    azimuth = np.arange(-90, 90, 1)
    array_loc = np.array(
        [
            -31.75,
            -31.25,
            -30.75,
            -30.25,
            -29.75,
            -29.25,
            -28.75,
            -28.25,
            -27.75,
            -27.25,
            -26.75,
            -26.25,
            -25.75,
            -25.25,
            -24.75,
            -24.25,
            -23.75,
            -23.25,
            -22.75,
            -22.25,
            -21.75,
            -21.25,
            -20.75,
            -20.25,
            -19.75,
            -19.25,
            -18.75,
            -18.25,
            -17.75,
            -17.25,
            -16.75,
            -16.25,
            -15.75,
            -15.25,
            -14.75,
            -14.25,
            -13.75,
            -13.25,
            -12.75,
            -12.25,
            -11.75,
            -11.25,
            -10.75,
            -10.25,
            -9.75,
            -9.25,
            -8.75,
            -8.25,
            -7.75,
            -7.25,
            -6.75,
            -6.25,
            -5.75,
            -5.25,
            -4.75,
            -4.25,
            -3.75,
            -3.25,
            -2.75,
            -2.25,
            -1.75,
            -1.25,
            -0.75,
            -0.25,
            0.25,
            0.75,
            1.25,
            1.75,
            2.25,
            2.75,
            3.25,
            3.75,
            4.25,
            4.75,
            5.25,
            5.75,
            6.25,
            6.75,
            7.25,
            7.75,
            8.25,
            8.75,
            9.25,
            9.75,
            10.25,
            10.75,
            11.25,
            11.75,
            12.25,
            12.75,
            13.25,
            13.75,
            14.25,
            14.75,
            15.25,
            15.75,
            16.25,
            16.75,
            17.25,
            17.75,
            18.25,
            18.75,
            19.25,
            19.75,
            20.25,
            20.75,
            21.25,
            21.75,
            22.25,
            22.75,
            23.25,
            23.75,
            24.25,
            24.75,
            25.25,
            25.75,
            26.25,
            26.75,
            27.25,
            27.75,
            28.25,
            28.75,
            29.25,
            29.75,
            30.25,
            30.75,
            31.25,
            31.75,
        ]
    )

    steering_vect = np.zeros((len(array_loc), len(azimuth)), dtype=complex)
    for idx, d in enumerate(array_loc):
        steering_vect[idx, :] = np.exp(
            -1j * 2 * np.pi * (d * np.sin(azimuth / 180 * np.pi))
        )

    spec_iaa = proc.doa_iaa(bv, steering_vect)

    npt.assert_almost_equal(
        spec_iaa,
        np.array(
            [
                19.1818677,
                19.2125349,
                18.85492539,
                16.818715,
                10.32716553,
                2.71991634,
                12.54114973,
                14.30517259,
                12.29636646,
                5.31560322,
                -6.30256417,
                4.01248093,
                3.30012642,
                -5.19065978,
                -9.53329134,
                -4.2938386,
                -9.65038927,
                -20.03183448,
                -11.80082119,
                -18.4377773,
                -22.06063644,
                -19.12238259,
                -37.81191793,
                -24.2258353,
                -32.23293179,
                -30.4889745,
                -32.90951,
                -37.22313763,
                -35.42747204,
                -41.94629394,
                -37.68904328,
                -40.11007894,
                -37.74929842,
                -39.14252472,
                -58.66251436,
                -44.16336749,
                -48.01842749,
                -46.6339406,
                -46.8589047,
                -55.84664506,
                -51.1181891,
                -47.79098239,
                -56.50261948,
                -53.06211109,
                -48.45967516,
                -51.64417486,
                -62.2252877,
                -48.2020312,
                -43.23833992,
                -41.12579125,
                -40.95581245,
                -41.2660267,
                -42.64661214,
                -44.73003566,
                -45.66679173,
                -48.66741834,
                -52.07915931,
                -59.39547166,
                -62.01172683,
                -62.74187353,
                -59.04150131,
                -67.4304658,
                -73.0600974,
                -76.77421008,
                -76.69677615,
                -75.55496477,
                -61.5548445,
                -69.91404527,
                -64.12556388,
                -68.91888198,
                -66.71770109,
                -64.3779267,
                -65.14030331,
                -71.3452626,
                -76.99626118,
                -76.23820342,
                -71.12219095,
                -76.66831102,
                -65.08619233,
                -62.55200945,
                -78.6161434,
                -74.04253373,
                -70.98613063,
                -60.64850947,
                -57.13588596,
                -25.34344414,
                -25.61500333,
                -58.19720664,
                -62.85271565,
                -67.08326695,
                -73.48382861,
                -76.95562124,
                -68.86341643,
                -68.99663931,
                -62.37968268,
                -66.3646328,
                -64.54647928,
                -64.42480713,
                -63.24303446,
                -64.58457151,
                -74.65297911,
                -67.37450746,
                -76.80270188,
                -69.88459946,
                -65.2727173,
                -70.00283561,
                -66.17230171,
                -62.77118441,
                -71.15226351,
                -64.15759798,
                -61.2982146,
                -56.38281659,
                -60.06863289,
                -53.66635843,
                -51.82677088,
                -49.93013803,
                -47.12640433,
                -44.24064455,
                -40.5764828,
                -37.44869182,
                -34.21042595,
                -31.52627662,
                -28.1438688,
                -25.09349289,
                -22.06688737,
                -19.08233419,
                -16.33812258,
                -13.70812199,
                -11.3513339,
                -9.22913605,
                -7.44864804,
                -6.12027591,
                -5.29887822,
                -5.16392241,
                -5.97109506,
                -8.9880499,
                -12.86879006,
                -31.36435399,
                -15.67367923,
                -12.72319162,
                -14.51039078,
                -21.24038786,
                -18.09048818,
                -15.78511221,
                -19.81235343,
                -22.14527174,
                -20.62577403,
                -29.36748863,
                -23.02713817,
                -28.37014565,
                -21.12608925,
                -26.09723027,
                -17.82292726,
                -23.96008978,
                -14.00077146,
                -22.09030764,
                -9.78867655,
                -22.22460562,
                -5.42273001,
                -24.50174884,
                -1.79105688,
                -7.90293291,
                -0.52452945,
                2.68361563,
                -16.3468071,
                5.63252176,
                6.67568328,
                -11.84627995,
                8.61435805,
                12.3218798,
                9.39646969,
                -1.05562404,
                14.15600635,
                18.00211481,
                18.1546135,
                14.17666356,
                -0.26998747,
                14.70397266,
                18.23270556,
                19.07229445,
            ]
        ),
        decimal=1,
    )


def test_doa_bartlett():
    """
    Test the DOA (Direction of Arrival) estimation using the Bartlett beamformer.
    """
    ps = proc.doa_bartlett(covmat_beamforming)

    npt.assert_almost_equal(
        ps,
        np.array(
            [
                -6.23256798,
                -6.21152132,
                -6.14848339,
                -6.04379417,
                -5.89812566,
                -5.7126165,
                -5.48901805,
                -5.22982064,
                -4.938333,
                -4.61869866,
                -4.27584719,
                -3.91539169,
                -3.5434937,
                -3.16672034,
                -2.79191695,
                -2.42611323,
                -2.07647431,
                -1.75030278,
                -1.45509449,
                -1.19865041,
                -0.98924898,
                -0.83588911,
                -0.74862198,
                -0.7390027,
                -0.82071109,
                -1.01041619,
                -1.32898902,
                -1.80318125,
                -2.46777599,
                -3.36750762,
                -4.55463184,
                -6.06242656,
                -7.77056673,
                -8.96624079,
                -8.31032215,
                -5.99932469,
                -3.37297293,
                -1.00296677,
                1.03312153,
                2.7722075,
                4.26157804,
                5.53958415,
                6.63457666,
                7.56693574,
                8.35108429,
                8.99699588,
                9.51124034,
                9.89768303,
                10.15793317,
                10.29160573,
                10.296435,
                10.16825763,
                9.90086521,
                9.48570946,
                8.91142334,
                8.16309861,
                7.22123667,
                6.0602922,
                4.64687043,
                2.93839889,
                0.88651331,
                -1.53577946,
                -4.20647262,
                -6.46045095,
                -7.05360348,
                -6.08177117,
                -4.78210933,
                -3.73038402,
                -3.00308867,
                -2.54456896,
                -2.28317489,
                -2.16404356,
                -2.16369358,
                -2.29729782,
                -2.61785931,
                -3.2081387,
                -4.16193034,
                -5.50920237,
                -6.87322278,
                -6.79749139,
                -4.45960606,
                -1.42028935,
                1.31542695,
                3.58646272,
                5.43649108,
                6.92752655,
                8.10874093,
                9.01515453,
                9.67054507,
                10.09001143,
                10.28161649,
                10.24719085,
                9.98238659,
                9.47594059,
                8.70790771,
                7.64629392,
                6.2409029,
                4.41203715,
                2.03014181,
                -1.11082848,
                -5.1890561,
                -8.67495369,
                -7.18106239,
                -4.29686858,
                -2.34701828,
                -1.2553487,
                -0.8270559,
                -0.95190169,
                -1.58311371,
                -2.71473825,
                -4.35365914,
                -6.42631133,
                -8.4405,
                -9.10036357,
                -7.94229778,
                -6.25015514,
                -4.84945888,
                -3.91099319,
                -3.42220803,
                -3.3480354,
                -3.66384309,
                -4.35678714,
                -5.41354901,
                -6.78187666,
                -8.26522076,
                -9.34993179,
                -9.38159076,
                -8.40576022,
                -7.08616995,
                -5.88535352,
                -4.96171954,
                -4.34202706,
                -4.01532725,
                -3.96485108,
                -4.17662609,
                -4.63985643,
                -5.34249023,
                -6.25964011,
                -7.32747133,
                -8.39447391,
                -9.17683867,
                -9.3504996,
                -8.84005661,
                -7.90143174,
                -6.84642094,
                -5.86200058,
                -5.02467013,
                -4.35458453,
                -3.84902942,
                -3.49761043,
                -3.28835149,
                -3.20990317,
                -3.25216062,
                -3.40622894,
                -3.6640936,
                -4.01810498,
                -4.46026908,
                -4.98127304,
                -5.56914173,
                -6.20744143,
                -6.87309287,
                -7.53426821,
                -8.14964408,
                -8.67121191,
                -9.05267739,
                -9.26237666,
                -9.29437831,
                -9.17000805,
                -8.92859812,
                -8.61421993,
                -8.2657737,
                -7.91282329,
                -7.57561329,
                -7.2669257,
                -6.99424361,
                -6.76157435,
                -6.57079056,
                -6.42254878,
                -6.31689181,
                -6.25362961,
                -6.23256798,
            ]
        ),
        decimal=1,
    )


def test_doa_capon():
    """
    Test the DOA (Direction of Arrival) estimation using the Capon beamformer.
    """
    ps = proc.doa_capon(covmat_beamforming)

    npt.assert_almost_equal(
        ps,
        np.array(
            [
                -10.19742531,
                -10.19693874,
                -10.19546992,
                -10.19299188,
                -10.18946106,
                -10.18481957,
                -10.17899842,
                -10.17192207,
                -10.16351448,
                -10.15370678,
                -10.14244694,
                -10.1297115,
                -10.11551932,
                -10.09994754,
                -10.08314889,
                -10.06536995,
                -10.04696876,
                -10.02842985,
                -10.01037395,
                -9.9935586,
                -9.97886549,
                -9.96726956,
                -9.95978522,
                -9.95738627,
                -9.96089788,
                -9.97086308,
                -9.98739026,
                -10.00999275,
                -10.03743528,
                -10.06760299,
                -10.09740612,
                -10.12272794,
                -10.13841462,
                -10.1382966,
                -10.11522288,
                -10.06108341,
                -9.96679091,
                -9.82219054,
                -9.61585988,
                -9.3347506,
                -8.96359855,
                -8.48398166,
                -7.8728113,
                -7.09985713,
                -6.12351664,
                -4.88318275,
                -3.2845658,
                -1.16970761,
                1.74263234,
                5.86058636,
                9.4081819,
                5.94129244,
                1.67756316,
                -1.36463263,
                -3.58585883,
                -5.2706823,
                -6.57774383,
                -7.60068691,
                -8.39908451,
                -9.0136166,
                -9.4740094,
                -9.80348979,
                -10.02144055,
                -10.14505308,
                -10.19037135,
                -10.17293022,
                -10.1080997,
                -10.01120144,
                -9.89743562,
                -9.78162217,
                -9.67771367,
                -9.59799764,
                -9.55192526,
                -9.54463575,
                -9.57547346,
                -9.63698113,
                -9.714805,
                -9.78860948,
                -9.83365423,
                -9.82241592,
                -9.72566034,
                -9.51256621,
                -9.14965531,
                -8.59822302,
                -7.80954469,
                -6.71604395,
                -5.21385966,
                -3.12463787,
                -0.1025276,
                4.5508309,
                9.39286197,
                4.57377175,
                -0.12463796,
                -3.18220375,
                -5.2995547,
                -6.82388039,
                -7.93380716,
                -8.73328673,
                -9.29027275,
                -9.65449183,
                -9.866543,
                -9.96281399,
                -9.9778528,
                -9.94470631,
                -9.89344868,
                -9.84843444,
                -9.82544391,
                -9.83023128,
                -9.85946354,
                -9.90381122,
                -9.95193034,
                -9.99395048,
                -10.02367518,
                -10.03937495,
                -10.0434269,
                -10.04114627,
                -10.03914544,
                -10.04356749,
                -10.05857215,
                -10.08542319,
                -10.12237228,
                -10.16528868,
                -10.20876285,
                -10.24732307,
                -10.27646247,
                -10.29330959,
                -10.29690601,
                -10.28813664,
                -10.2693926,
                -10.24405512,
                -10.21589075,
                -10.18845086,
                -10.16456725,
                -10.14602053,
                -10.13342533,
                -10.1263301,
                -10.12348452,
                -10.12319853,
                -10.12371166,
                -10.12350661,
                -10.12152671,
                -10.11728368,
                -10.11086237,
                -10.10284206,
                -10.09416011,
                -10.08594498,
                -10.0793446,
                -10.07537244,
                -10.07478843,
                -10.07802522,
                -10.08516291,
                -10.09594827,
                -10.10984911,
                -10.12613089,
                -10.14394252,
                -10.16239957,
                -10.18065632,
                -10.19796147,
                -10.21369574,
                -10.22739196,
                -10.23874005,
                -10.24758008,
                -10.25388681,
                -10.25774893,
                -10.2593457,
                -10.25892331,
                -10.25677235,
                -10.25320776,
                -10.24855169,
                -10.2431198,
                -10.23721073,
                -10.23109877,
                -10.2250293,
                -10.21921649,
                -10.21384286,
                -10.20906021,
                -10.20499143,
                -10.20173268,
                -10.19935578,
                -10.19791031,
                -10.19742531,
            ]
        ),
        decimal=1,
    )
